package com.thingcom.chinamobile.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @ClassName PropertyConfigAnalyze
 * @Description .properties配置文件的解析处理
 * @Author zhou tao
 * @Date 2019/12/16 15:38
 * @Version 1.0
 **/
@Slf4j
public class PropertyConfigAnalyze implements ConfigAnalyze {

	@Override
	public Map<String, String> analyze(String path) {
		try {
			Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource(path));
			Map<String, String> parmas = new HashMap<>(properties.size());
			Set<String> keys = properties.stringPropertyNames();
			for (String key : keys) {
				parmas.put(key, properties.getProperty(key));
			}
			return parmas;
		} catch (IOException e) {
			log.error("解析配置文件失败");
			return null;
		}
	}
}
